package com.hp.attendance.serlvet.overtime;

import com.hp.attendance.entity.Overtime;
import com.hp.attendance.service.OvertimeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

@WebServlet("/updOvertime")
public class OvertimeUpdServlet extends HttpServlet {
    private OvertimeService overtimeService=new OvertimeService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //修改
        try {
            Date date = new Date();
            String department_number = req.getParameter("department_number");//department_number
            String employee_numbe = req.getParameter("employee_number");
            String dateTime = req.getParameter("date");
            date = new SimpleDateFormat("yyyy-MM-dd").parse(dateTime);

            String id = req.getParameter("id");
            Overtime overtime = new Overtime();
            overtime.setDepartment_number(Integer.valueOf(department_number));
            overtime.setEmployee_number(Integer.valueOf(employee_numbe));
            overtime.setDay(date);
            overtime.setId(Integer.valueOf(id));
            overtime.setStart_time(null);
            overtime.setEnd_time(null);
            overtime.setNotes(null);
            overtimeService.updateOvertime(overtime);
            req.getRequestDispatcher("/overtimeList").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
